// 用户登录信息存储
import { defineStore } from 'pinia';

export const useUserStore = defineStore('user', {
    state: () => ({
        userInfo: {
            name: '',
            token: '',
            router: '',
            id: 0,
            studengOrteacherId: 0,
        },
    }),
    actions: {
        setUserInfo(name: string, token: string,router: string,id: number,studengOrteacherId: number) {
            this.userInfo.name = name;
            this.userInfo.token = token;
            this.userInfo.router = router;
            this.userInfo.id = id;
            this.userInfo.studengOrteacherId = studengOrteacherId;
        },
        // 退出登录方法
        logout() {
            // 清空用户信息
            this.userInfo = {
                name: '',
                token: '',
                router: '',
                id: 0,
                studengOrteacherId: 0,
            };
            // 因为 persist: true，localStorage 中的数据会自动被清空
        },
    },
    // 只需要添加这一行即可！
    persist: true,
});
